package com.you.atlas.biz.place.service.impl;

import com.you.atlas.biz.place.service.SmallNoteService;
import com.you.place.dal.dao.SmallNoteDAO;
import com.you.place.dal.dao.VoteDAO;
import com.you.place.dal.dao.dataobject.SmallNoteDO;
import com.you.place.dal.dao.dataobject.VoteDO;

public class SmallNoteServiceImpl implements SmallNoteService {

    private VoteDAO      voteDAO;
    private SmallNoteDAO smallNoteDAO;

    public void setVoteDAO(VoteDAO voteDAO) {
        this.voteDAO = voteDAO;
    }

    public void setSmallNoteDAO(SmallNoteDAO smallNoteDAO) {
        this.smallNoteDAO = smallNoteDAO;
    }

    @Override
    public boolean addNote(SmallNoteDO smallNoteDO) {
        return smallNoteDAO.create(smallNoteDO) != null;
    }

    @Override
    public boolean deleteNote(Long id,Long memberId) {
        return smallNoteDAO.delete(id,memberId) > 0;
    }

    @Override
    public boolean up(Long id, Long memberId) {
        if (voteDAO.findUp("small_note", id, memberId) == null) {
            voteDAO.create(new VoteDO("up", "small_note", id, memberId));
            return smallNoteDAO.updateUsefulCount(id) > 0;
        }
        return false;
    }

}
